/**
 * 搜索引擎配置
 * 统一管理搜索引擎的配置信息
 */

export const SEARCH_ENGINES = {
  BAIDU: {
    name: '百度',
    placeholder: '百度...',
    icon: '../assets/baidu.svg',
    searchUrl: 'https://www.baidu.com/s?wd=',
    paramKey: 'wd'
  },
  GOOGLE: {
    name: '谷歌',
    placeholder: '谷歌...',
    icon: '../assets/Google@1x.svg',
    searchUrl: 'https://www.google.com/search?q=',
    paramKey: 'q'
  }
};

/**
 * 构建搜索URL
 * @param {string} engine - 搜索引擎类型
 * @param {string} query - 搜索关键词
 * @returns {string} 完整的搜索URL
 */
export const buildSearchUrl = (engine, query) => {
  const config = SEARCH_ENGINES[engine];
  if (!config || !query.trim()) {
    return '#';
  }
  return `${config.searchUrl}${encodeURIComponent(query.trim())}`;
};

/**
 * 执行搜索
 * @param {string} engine - 搜索引擎类型
 * @param {string} query - 搜索关键词
 */
export const performSearch = (engine, query) => {
  const url = buildSearchUrl(engine, query);
  if (url !== '#') {
    window.location.href = url;
  }
};